package com.yohann.boot.config;

import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.time.Duration;

/**
 * restTemplate 配置类
 *
 * @author Yeung Wah
 * @since 2021/9/14
 */
@Configuration
public class RestTemplateConfig {
    @Bean
    public RestTemplate restTemplate() {
        FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
        Duration duration = Duration.ofSeconds(5);
        return new RestTemplateBuilder()
                .setConnectTimeout(duration)
                .setReadTimeout(duration)
                .additionalMessageConverters(converter)
                .build();
    }
}